public class BrianryTree {
    public class TreeNode {
        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

    }

    public TreeNode root = null;

    public TreeNode Search(int key) {
        TreeNode cur = root;
        while (cur != null) {
            if (cur.val < key) {
                cur = cur.right;
            } else if (cur.val > key) {
                cur = cur.left;
            } else {
                return cur;
            }
        }
        return null;

    }

    public void insert(int key) {
        TreeNode Node = new TreeNode(key);

        if (root == null) {
            root = Node;
            return;
        }
        TreeNode cur = root;
        TreeNode pre = null;
        while (cur != null) {
            if (cur.val < key) {
                pre = cur;
                cur = cur.right;
            } else if (cur.val > key) {
                pre = cur;
                cur = cur.left;
            } else {
                return;
            }
        }
        if(pre.val>key){
            pre.left=Node;
        }else{
            pre.right=Node;
        }
    }
}